module(..., package.seeall) -- 使得文件中的函数在何处都可调用
require "sys"
require "pins"
require "net"
require "earthquakeWaringDril"
require "earthquakeWaring"
pmd.ldoset(15, pmd.LDO_VLCD)
local ledon = true -- led是否开启
local pin5 = pins.setup(pio.P0_5, 0) -- 正常是低电平，模块开机时输出高
local function powerOnIndicatorLogic()
    if ledon then
        pins.close(pio.P0_13)
        pin5(1)
        pio.pin.pwm(13, 50, 600, -1)
    else
        pins.close(pio.P0_13)
        pin5(0)
        pio.pin.pwm(13, 0, 0, -1)

    end
    if earthquakeWaringDril.DoLampTask and earthquakeWaring.DoLampTaskEarthquake then
        if net.getNetMode() ~= 0 and net.getRssi() >= 11 then
            ledon = not ledon
        else
            ledon = true
            pins.setup(pio.P0_13, 1)
        end
    elseif not earthquakeWaringDril.DoLampTask or
        not earthquakeWaring.DoLampTaskEarthquake then
        ledon = false
        pin5(0)
        pins.setup(pio.P0_13, 0)
    end

    sys.timerStart(powerOnIndicatorLogic, 500) -- 一秒后执行指定函数
end
powerOnIndicatorLogic()
